/*
 * FileSys.cpp
 *
 *  Created on: Jul 14, 2009
 *      Author: yoav
 */

#include "FileSys.h"

FileSys::FileSys(char* conf) {
	hd = new HardDisk(conf);

}

FileSys::~FileSys() {
	cout << "FileSys dtor" << endl;
	delete hd;
}

/* creates a file returning its i_node number. Flag indicates whether the file to create is a regular file or a soft link. **/

int FileSys::createFile(int flag) {
	int ans = -1;
	if (flag == SOFT_LINK) {//soft link
		ans = hd->allocateInode();
		hd->setInodeType(ans, SOFT_LINK);
	} else if (flag == FILE) {//regular file
		ans = hd->allocateInode();
		hd->setInodeType(ans, FILE);

	} else if (flag == DIRECTORY) {
		ans = hd->allocateInode();
		hd->setInodeType(ans, DIRECTORY);
	}
	return ans;
}
/*creates a directory, returning its i_node number.*/
int FileSys::createDir() {
	return createFile(DIRECTORY);//dir will be created as regular file
}

/* Returns the type of the file this i_node represents.*/
int FileSys::getFileType(int i_node) {
	return hd->getInodeType(i_node);
}
/*reads nBytes (at most) from the given file (represented by this i_node) at the given offset inside the file into the buffer.	 **/
void FileSys::f_read(int i_node, char* buffer, int offset, int nBytes) {
	int position=0;
	//int blockNum=hd->kalEl.blockSize;
	char ansBuf[hd->kalEl.blockSize];


}

/*
 * writes nBytes (at most) to the given file (represented by this i_node)
 *  at the given offset inside that file, from the buffer.
 *  If the amount to be written exceeds the current allocated block,
 *  a new block should be allocated to accommodate the rest of the data.
 */
void FileSys::f_write(int i_node, char* buffer, int offset, int nBytes) {

}

/*
 * reads the entire content of the directory file specified by the given i_node.
 * This information is then entered into a data structure (a vector or list)
 * that lists the files in this directory.
 * Each element in this list therefore contains a filename and i_node number.
 */
vector<iFile> FileSys::d_read(int i_node) {

}

/*
 * replaces the content of the given directory file (specified by i_node)
 * with the information stored in the list.
 * The list has the same format as that returned by d_read().
 */
void FileSys::d_write(int i_node, vector<iFile> dirList) {

}

/* delete the file.	 */
void FileSys::f_delete(int i_node) {

}
/*delete the directory if it is empty.	 */
void FileSys::d_delete(int i_node) {

}
